﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;

namespace Blokus.Scenes
{
    public class SceneCredits : Scene
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        private SpriteFont menuFont;


        private List<string> menuItems = new List<string>();
        private int currentMenuIndex = 0;
        private KeyboardState keyPrevState;
        private GamePadState gpPrevState;
        private Texture2D texBG;
        private float aspectRatio;
        private RenderTarget2D backgroundRenderTarget;

        public SceneCredits()
        {
            menuItems.Add("This game is brought to you by:");
            menuItems.Add("Nick Walker");
            menuItems.Add("BJ Randall");
        }

        public override void LoadContent(ContentManager content, GraphicsDeviceManager graphics)
        {
            this.graphics = graphics;
            //load font
            menuFont = content.Load<SpriteFont>("gamefont");
            backgroundRenderTarget = new RenderTarget2D(graphics.GraphicsDevice, 1280, 800);
            spriteBatch = new SpriteBatch(graphics.GraphicsDevice);

            //texBG = content.Load<Texture2D>("Textures\\background");
            aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio;


        }

        public override Blokus.GameState Update(GameTime gameTime)
        {
            //number of menu items minus one
            //get keys
            GamePadState currGPState = GamePad.GetState(PlayerIndex.One);
            bool kEnter = Keyboard.GetState().IsKeyDown(Keys.Enter) && !keyPrevState.IsKeyDown(Keys.Enter)
                || Keyboard.GetState().IsKeyDown(Keys.Escape) && !keyPrevState.IsKeyDown(Keys.Escape)
                || currGPState.IsButtonDown(Buttons.A) && !gpPrevState.IsButtonDown(Buttons.A)
                || currGPState.IsButtonDown(Buttons.B) && !gpPrevState.IsButtonDown(Buttons.B);



            //check for menu item selected
            if (kEnter)
            {
                return Blokus.GameState.MENU;
            }

            //reset previous keyboard state
            keyPrevState = Keyboard.GetState();
            gpPrevState = GamePad.GetState(PlayerIndex.One);

            return Blokus.GameState.CREDITS;
        }

        public override void Draw(GameTime gameTime)
        {
            graphics.GraphicsDevice.Clear(colorMiddle);
           // graphics.GraphicsDevice.SetRenderTarget(backgroundRenderTarget);

            spriteBatch.Begin();
            spriteBatch.Draw(texBG, new Rectangle(0, 0, 1280, 800), Color.White);
            //credits items
            for (int ct = 0; ct < menuItems.Count; ct++)
            {
                Color clr = colorLightest;
                string menuStr = menuItems[ct];
                int dx = 0;
                if (ct == 0)
                    dx = -170;
                spriteBatch.DrawString(menuFont, menuStr, new Vector2(440 + dx, 250 + ct * 50), clr);
            }
            spriteBatch.End();

            //BackgroundEffects.drawBGEffects(gameTime, aspectRatio, backgroundRenderTarget);
        }
        public override void ResetPrevKeys()
        {
            keyPrevState = Keyboard.GetState();
            gpPrevState = GamePad.GetState(PlayerIndex.One);
        }

    }
}
